import java.util.Arrays;

/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: MENG
 * Date: 2022-06-15
 * Time: 21:31
 */
class Alg2{
    //静态的泛型方法 需要在static后用<>声明泛型类型参数
    public static <T extends Comparable> T findMaxVal(T[] array){
        T maxVal = array[0];
        for (int i = 0; i < array.length; i++) {
            if( array[i].compareTo(maxVal) > 0 ){
                maxVal = array[i];
            }
        }
        return maxVal;
    }
}

class Alg<T extends Comparable>{
    public T findMaxVal(T[] array){
        T maxVal = array[0];
        for (int i = 0; i < array.length; i++) {
            if( array[i].compareTo(maxVal) > 0 ){
                maxVal = array[i];
            }
        }
        return maxVal;
    }
}

public class Test1 {

    //静态方法，不用创建对象，直接用类名.方法名即可访问
    public static void main(String[] args) {
        Integer[] array = {1,2,3,14};
        int ret = Alg2.<Integer>findMaxVal(array);
        System.out.println(ret);

    }

    //普通方法要创建对象来访问方法
    public static void main1(String[] args) {
        Alg<Integer> alg = new Alg<>();
        Integer[] array = {1,2,3,4};
        int ret = alg.findMaxVal(array);
        System.out.println(ret);

    }
}
